package com.service.cook.imp;

import java.util.List;
import java.text.SimpleDateFormat;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dao.cook.CtodaymenuDaoY;
import com.po.TodaymenuY;
import com.po.TomorrowmenuY;
import com.service.cook.CtodaymenuServiceY;

@Service
public class CtodaymenuServiceImpY implements CtodaymenuServiceY {
	@Resource(name = "ctodaymenuDaoImpY")
	private CtodaymenuDaoY ctodaymenuDaoY;
    
	
	@Override
	public List<TodaymenuY> getTodayMenuList() {
		List<TodaymenuY> list = ctodaymenuDaoY.getTodayMenuList();
		return list;
	}

	@Override
	public int addTodayMenus(List<TomorrowmenuY> menu) {
		ctodaymenuDaoY.delTodayMenu();
		int i = ctodaymenuDaoY.addTodayMenus(menu);
		return i;
	}

	@Override
	public int delTodayMenu() {
		int i = ctodaymenuDaoY.delTodayMenu();
		return i;
	}

	@Override
	public int havetoday() {
		List<TodaymenuY> list = ctodaymenuDaoY.getTodayMenuList();
		java.sql.Date data1 = new java.sql.Date(System.currentTimeMillis());
		if (list.size() != 0) {
			TodaymenuY todaymenu = list.get(0);
			java.sql.Date data2=todaymenu.getMenu_time();
			SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd");
			String s=f.format(data1);
			String u=f.format(data2);
			if (s.equals(u))
				return 1;
			else return 0;
		} else
			return 0;
	}

	@Override
	public TodaymenuY getTodaymenu(String id) {
		TodaymenuY todaymenu=ctodaymenuDaoY.getTodaymenu(id);
		return todaymenu;
	}

}
